let http = require('http');
let fs = require('fs');

let app = http.createServer((req,res)=>{

    // 
    console.log(req.url);

    // new URL 方法 解析 路径
    // 参数1：原始路径 /index.html?name=laowang&age=18
    // 参数2：主机地址
    let url = new URL(req.url,'http://localhost');

    // console.log(url);

    if(url.pathname === '/index.html'){
        let data = fs.readFileSync('./index.html');
        // console.log(data);

        console.log('查询字符串打印',url.searchParams.get('a'));
        res.end(data);
    }
})

app.listen(80,()=>{
    console.log("启动成功");
})